import express from "express";
import userService from "./services/userService";
import os from "os";
import numeral from "numeral"; // MB 单位格式转换
import tinypngService from "./services/tinypngService";

const router = express.Router();

// 添加一个用户
router.get('/add_user', userService.add_user);
// 获取用户信息
router.get('/get_user_info', userService.get_user);
//ping
router.get('/ping', async (req: express.Request, res: express.Response, next: express.NextFunction) => {
    res.send(JSON.stringify({
        cup: os.cpus().length, // 获取CPU信息  
        totalmem: numeral(os.totalmem()).format('0.0b'), // 总内存
        freemem: numeral(os.freemem()).format('0.0b'),// 空闲内存
    }))
});

// tingpng相关的接口
router.get('/get_key_list', tinypngService.get_key_list_verify, tinypngService.get_key_list); //分页获取key
router.post('/add_key', tinypngService.add_key_verify, tinypngService.add_key); //添加key
router.get('/del_key', tinypngService.del_key_verify, tinypngService.del_key); //删除key
router.get('/get_key_by_conut', tinypngService.get_key_by_conut_verify, tinypngService.get_key_by_conut);//获取当前最大可用额度key
router.get('/validate_all_key', tinypngService.validate_all_key); // 校验所有的key值
router.post('/update_residue', tinypngService.update_residue_verify, tinypngService.update_residue); //更新余额

// 接口响应测试相关接口
router.get('/get_api_response_test', tinypngService.get_api_response_test); // 获取接口响应测试数据
router.post('/save_api_response_test', tinypngService.save_api_response_test); // 保存接口响应测试数据
router.get('/clear_api_response_test', tinypngService.clear_api_response_test); // 清空接口响应测试数据


export default router;